//
//  ZLExciseBeginQuestionListTableViewCell.m
//  ZLExamination
//
//  Created by Lei_Zhong_Xun on 2017/9/5.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExciseBeginQuestionListTableViewCell.h"

@implementation ZLExciseBeginQuestionListTableViewCell

#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setMultipleIsSelected:(BOOL)multipleIsSelected {
    _multipleIsSelected = multipleIsSelected;
    _optionsLbl = nil;
    _optionsLbl = [self getMultipleOptionsLblWithMultipleIsSelected:multipleIsSelected];
    
    [self.contentView addSubview:_optionsLbl];
    [self.contentView addSubview:self.questionLbl];
    
    [_optionsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.left.mas_equalTo(12);
        make.width.height.mas_equalTo(30);
    }];
    
    [_questionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_optionsLbl.mas_top).offset(-4);
        make.left.equalTo(_optionsLbl.mas_right).offset(15);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(-12);
        make.height.greaterThanOrEqualTo(@40);
    }];
}

- (void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;
    _optionsLbl = nil;
    _optionsLbl = [self getOptionsLblWithIsSelected:isSelected];
    
    [self.contentView addSubview:_optionsLbl];
    [self.contentView addSubview:self.questionLbl];
    
    [_optionsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.left.mas_equalTo(12);
        make.width.height.mas_equalTo(30);
    }];
    
    [_questionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_optionsLbl.mas_top).offset(-4);
        make.left.equalTo(_optionsLbl.mas_right).offset(15);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(-12);
        make.height.greaterThanOrEqualTo(@40);
    }];
    
}

#pragma mark - 获得单选选项
- (UILabel *)getOptionsLblWithIsSelected:(BOOL)isSelected {
    UILabel *optionsLbl = [self layerSettingsWithCornerRadius:15 withSelected:isSelected];
    return optionsLbl;
}

#pragma mark - 获得多选选项
- (UILabel *)getMultipleOptionsLblWithMultipleIsSelected:(BOOL)multipleIsSelected {
    UILabel *optionsLbl = [self layerSettingsWithCornerRadius:5 withSelected:multipleIsSelected];
    return optionsLbl;
}

- (UILabel *)layerSettingsWithCornerRadius:(CGFloat)radius withSelected:(BOOL)selected {
    UILabel *optionsLbl = [[UILabel alloc] init];
    optionsLbl.layer.cornerRadius = radius;
    optionsLbl.textAlignment = NSTextAlignmentCenter;
    optionsLbl.layer.masksToBounds = YES;
    if (selected) {
        optionsLbl.backgroundColor = kMY_BLUE_COLOR;
        optionsLbl.textColor = [UIColor whiteColor];
    } else {
        optionsLbl.backgroundColor = [UIColor whiteColor];
        optionsLbl.layer.borderColor = [kMY_BLUE_COLOR CGColor];
        optionsLbl.layer.borderWidth = 0.5;
        optionsLbl.textColor = kMY_BLUE_COLOR;
    }
    return optionsLbl;
}
#pragma mark - lazy load
- (UILabel *)questionLbl {
    if (!_questionLbl) {
        _questionLbl = [[UILabel alloc] init];
        _questionLbl.font = kMyFont(15);
        _questionLbl.textColor = [UIColor darkGrayColor];
        _questionLbl.numberOfLines = 0;
        [_questionLbl sizeToFit];
    }
    return _questionLbl;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
